package com.zmn.oms.third.daowei;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 类描述：到位-常量类
 *
 * @author lhl
 * @date 2020/02/21 15:01
 */
@Component
public final class DaoweiConsts {

    public static final String NAME_KYX = "到位快益修";
    public static final String NAME_APP = "到位APP";
    public static final String NAME_DTW = "到位电通王";
    public static final String NAME_ZX = "到位直选";

    public static final int CHANNEL_ID_KYX = 33551;
    public static final int CHANNEL_ID_APP = 1210;
    public static final int CHANNEL_ID_DTW = 10108;
    public static final int CHANNEL_ID_ZX = 32809;

    public static String DAOWEI_API_URL;
    public static Integer SCALP_ID; // 刷单ID，取消缘由中，存在有此ID的条目时，标识该单为刷单  2021.09.15 by lhl

    @Value("${daowei.url.api-invok:''}")
    private void setDaoweiApiUrl(String url){
        this.DAOWEI_API_URL = url;
    }
    @Value("${daowei.scalpid:101}")
    private void setDaoweiScalpId(Integer scalpId){
        this.SCALP_ID = scalpId;
    }


    //到位快益修配置参数
    public static String APPKEY_KYX = "cpn8xgithiy5z7vk4nb2c8kvucv5kh6e";
    public static String SECRET_KYX = "kb7lm4tdy4ewd5l21m1zws38cbq0dte0";

    // 到位APP配置参数
    public static String APPKEY_APP = "3f57600df8da432cb7b88b00acea9a31";	// 老appkey，已弃用
    public static String APPKEY_APP_CLEAN = "b4ae6806f5f148388e9f8c3101373269";	// 清洗店铺ID
    public static String APPKEY_APP_REPARI = "857c1ef45c9e488c947c35b8f9cb68aa";	// 家修店铺ID
    public static String SECRET_APP = "0274a76a3c2a4ba39932d6d241bce234";

    //到位电通王配置参数
    public static String APPKEY_DTW = "q5dytuhz9ug7noivnxez6w1o8cmmae7x";
    public static String SECRET_DTW = "xea55rgeck01fwho5okn15cj1neeboen";


    /**
     * 到位订单状态
     */
    public static final String SYNC_STATUS_ONGOING = "ongoing";		//（商家接单）
    public static final String SYNC_STATUS_CANCELED = "canceled";		//（商家取消）
    public static final String SYNC_STATUS_COMPLETED = "completed";		//（商家确认完成）
    public static final String SYNC_STATUS_APPROVE_REFUND = "approve_refund";	//（同意用户退款请求）
    public static final String SYNC_STATUS_REJECT_REFUND = "reject_refund";	//（拒绝用户退款请求）
    public static final String SYNC_STATUS_SET_DIFF = "set_diff";		//（设置补差价金额）
    public static final String SYNC_STATUS_ORDER_DIFF = "order_diff";		//（在商家平台补差价）

    /**
     * 退款申请标识的key，在做该渠道订单的取消操作时，标识操作是否由申请退款触发
     */
    public static final String EXTRA_TAG_APPLY_REFUND = "daowei_tag_apply_refund";

    /**
     * 同步日志标识
     */
    public static final int SYNC_LOG_ONGOING = 601;		    // 商家接单
    public static final int SYNC_LOG_CANCELED = 602;		// 商家取消
    public static final int SYNC_LOG_COMPLETED = 603;		// 商家确认完成
    public static final int SYNC_LOG_APPROVE_REFUND = 604;	// 同意用户退款请求
    public static final int SYNC_LOG_REJECT_REFUND = 605;	// 拒绝用户退款请求
    public static final int SYNC_LOG_SET_DIFF = 606;		// 设置补差价金额
    public static final int SYNC_LOG_ORDER_DIFF = 607;		// 在商家平台补差价
    public static final int SYNC_LOG_DUTY_TIME = 608;		// 预约时间

    /**
     * 获取同步日志标识名称
     * @param code
     * @return
     */
    public static String getSyncLogName(int code) {
        switch (code) {
            case SYNC_LOG_ONGOING:
                return "商家接单";
            case SYNC_LOG_CANCELED:
                return "订单取消";
            case SYNC_LOG_COMPLETED:
                return "订单完成";
            case SYNC_LOG_APPROVE_REFUND:
                return "同意退款";
            case SYNC_LOG_REJECT_REFUND:
                return "拒绝退款";
            case SYNC_LOG_SET_DIFF:
                return "应补差价";
            case SYNC_LOG_ORDER_DIFF:
                return "平台代收金额";
            case SYNC_LOG_DUTY_TIME:
                return "预约时间";
            default:
                return "未知";
        }
    }

    /**
     * 获取到位渠道名称
     * @param channelId
     * @return
     */
    public static final String getChannelName(Integer channelId) {
        if (channelId == null) {
            return "到位-null";
        }

        switch (channelId.intValue()) {
            case CHANNEL_ID_KYX :
                return NAME_KYX;
            case CHANNEL_ID_DTW :
                return NAME_DTW;
            case CHANNEL_ID_APP :
                return NAME_APP;
            case CHANNEL_ID_ZX :
                return NAME_ZX;
            default:
                return String.format("到位-%d", channelId.intValue());
        }
    }

    /**
     * 获取渠道
     * @param appkey
     * @param isQuick 是否是直选订单
     * @return
     */
    public static final ChannelInfo channelInfo(String appkey, boolean isQuick) {
        ChannelInfo channelInfo = null;
        // 到位APP
        if (APPKEY_APP.equals(appkey) || APPKEY_APP_CLEAN.equals(appkey) || APPKEY_APP_REPARI.equals(appkey)) {
            channelInfo = new ChannelInfo(CHANNEL_ID_APP, NAME_APP, appkey, SECRET_APP);
        }
        // 到位快益修
        else if (APPKEY_KYX.equals(appkey)) {
            channelInfo = new ChannelInfo(CHANNEL_ID_KYX, NAME_KYX, appkey, SECRET_KYX);
        }
        // 到位点通王
        else if (APPKEY_DTW.equals(appkey)) {
            channelInfo = new ChannelInfo(CHANNEL_ID_DTW, NAME_DTW, appkey, SECRET_DTW);
        }

        // 到位直选
        if (channelInfo != null && isQuick) {
            channelInfo.setId(CHANNEL_ID_ZX);
            channelInfo.setName(channelInfo.getName()+ "-直选");
        }

        return channelInfo;
    }

    /**
     * 私有构造器，禁止外部实例化
     */
    private DaoweiConsts() {}

    /**
     * 渠道信息模型
     */
    @Data
    public static class ChannelInfo {
        private int id;

        private String name;

        private String appkey;

        private String secret;

        public ChannelInfo(int id, String name, String appkey, String secret) {
            this.id = id;
            this.name = name;
            this.appkey = appkey;
            this.secret = secret;
        }
    }
}
